package com.woniuxy.day11springmvc.controller;

import com.woniuxy.day11springmvc.entity.User;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: linKe
 * @Date: 2021/11/23 10:08
 * @FileName: RoleController
 * @version: 1.0
 * @Description: 描述
 */
@Log4j2
@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 类型一
     * <p>
     * 传对象主要是增加约束
     *
     * @param user 用户实体对象
     * @return user对象
     */
    @PostMapping("/one")
    public User findOne(@RequestBody User user) {

        //日志打印
        log.info(user);
        return user;
    }

    /**
     * 类型二
     * <p>
     * 传数组 前端 传参[1,2,3]
     *
     * @param user 数组对象
     * @return user
     */
    @PostMapping("/int")
    public int[] findInt(@RequestBody int[] user) {

        //日志打印  [1, 2, 3]
        log.info(Arrays.toString(user));
        return user;
    }

    /**
     * 类型三
     * <p>
     * 传集合 前端 传参[1,2,3]
     *
     * @param user 集合对象
     * @return user
     */
    @PostMapping("/list")
    public List<?> findList(@RequestBody List<Integer> user) {

        //日志打印  [1, 2, 3]
        log.info(user);
        return user;
    }

    /**
     * 类型四
     * <p>
     * 传Map 前端 传参{"id":2,"name":"add","list":[1,2,3],"object":{"id":2,"name":"3www"}}
     *
     * @param user Map对象 什么类型都可以接收
     * @return user
     */
    @PostMapping("/map")
    public Map<String, Object> findMap(@RequestBody Map<String, Object> user) {

        //日志打印  {"id":2,"name":"add","list":[1,2,3],"object":{"id":2,"name":"3www"}}
        log.info(user);
        return user;
    }

    /**
     * 类型五
     * <p>
     * 传String 前端 传参{"id":2,"name":"add","list":[1,2,3],"object":{"id":2,"name":"3www"}}
     *
     * @param user Map对象 什么类型都可以接收
     * @return user
     */
    @PostMapping("/str")
    public String findMap(@RequestBody String user) {

        //日志打印  {"id":2,"name":"add","list":[1,2,3],"object":{"id":2,"name":"3www"}}
        log.info(user);
        return user;
    }
}
